package com.project.service;

import com.project.bean.CutPageBean;
import com.project.bean.UserBean;
import com.project.dao.IUserDao;
import com.project.dao.impl.UserDaoImpl;
import com.project.server.Request;
import com.project.server.Response;
import com.project.server.Servlet;

public class CutAllService implements Servlet {

    private IUserDao dao = new UserDaoImpl();

    public void service(Request request, Response response){

        String str = request.getParameter("pageNo");
        int pageNo = str == null ? 1 : Integer.parseInt(str);

       CutPageBean<UserBean> cutBean = dao.catAll(pageNo);
       String infoStr = "<table border='1' width='60%'>";
       infoStr += "<thead><tr><th>编号</th><th>用户名</th><th>密码</th>" +
        "<th>生日</th><th>电话</th></tr></thead>";
       infoStr += "<tbody>";

       for (UserBean user : cutBean.getList() ){
           infoStr += "<tr><td>"+user.getId()+"</td><td>"+user.getUserName()+"</td>" +
                   "<td>"+user.getPwd()+"</td><td>"+user.getBirthday()+"</td>" +
                   "<td>"+user.getPhone()+ "</td></tr>";
       }

       infoStr += "</tbody></table>";
       for (int i = 1 ; i <= cutBean.getPageSize(); i++){
           infoStr += "<a href='cutAll?pageNo="+i+"'>"+i+"</a> ";

       }

       response.sendMessage(infoStr);
    }
}
